﻿using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Xml.Serialization;
using System.Security.Cryptography;
using System.Text;

namespace churchtool.Plugin.SermonUpload.Data
{
    public class FtpConnectionSettings
    {
        private static FtpConnectionSettings singelton;

        private FtpConnectionSettings()
        {
            SourceFile = new List<string>();
        }

        [XmlElement(DataType = "string", ElementName = "Host")]
        public string Host;

        [XmlElement(DataType = "string", ElementName = "Username")]
        public string Username;

        [XmlIgnore]
        public string Password;

        public string EncPassword
        {
            get
            {
                return Crypto.Encrypt(Password);
            }
            set
            {
                Password = Crypto.Decrypt(value);
            }
        }

        [XmlElement(DataType = "string", ElementName = "TargetFolder")]
        public string TargetFolder;

        public List<string> SourceFile;
        public bool Passive;
        public int Port = 21;

        public bool isComplete()
        {
            if (Host == null || Host.Equals(string.Empty) ||
                Username == null || Username.Equals(string.Empty) ||
                Password == null || Password.Equals(string.Empty) ||
                SourceFile == null || SourceFile.FirstOrDefault().ToString().Equals(string.Empty))
                return false;

            return true;
        }

        public static FtpConnectionSettings GetInstance()
        {
            if (singelton == null)
            {
                if (singelton == null)
                    singelton = new FtpConnectionSettings();
            }

            return singelton;
        }
    }
}
